package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.api.mapper.UserMapper;
import com.tanhua.model.db.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 用户服务接口实现类
 */
@DubboService
public class UserApiImpl implements UserApi{

    @Autowired
    private UserMapper userMapper;


    /**
     * 根据手机号查询用户对象
     *
     * @param phone
     * @return
     */
    @Override
    public User findByMobile(String phone) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mobile",phone);
        return userMapper.selectOne(queryWrapper);
    }

    /**
     * 新增新用户
     *
     * @param user
     */
    @Override
    public Long add(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    /**
     * 根据用户id更新环信账号跟密码
     *
     * @param user
     */
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    /**
     * 通过环信id查询用户
     *
     * @param huanxinId
     * @return
     */
    @Override
    public User findByHuanxinUser(String huanxinId) {
        return userMapper.selectOne(new QueryWrapper<User>().eq("hx_user",huanxinId));
    }

    /**
     * 根据主键id查询tb_user
     *
     * @param personUserId
     * @return
     */
    @Override
    public User findById(Long personUserId) {
        return userMapper.selectById(personUserId);
    }
}
